using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using ErkerTech.DeltaScope.Engine;

namespace ErkerTech.DeltaScope.App.Models
{
    public class DeltaScopeEngine
    {
        public TimeSpan ElapsedTime { get; private set; }
        public long PeakMemoryUsage { get; private set; }
        public IList<DeltaBlock> Compare(string tsLeftFile, string tsRightFile, bool bCaseSensitive = true)
        {
            //GC.Collect();
            //var process = Process.GetCurrentProcess();
            //process.Refresh();
            //var peakWorkingSet64 = process.PeakWorkingSet64;

            //var sw = new Stopwatch();
            //sw.Start();

            IList<DeltaBlock> results;
            using (var deltaEngine = new DeltaEngine())
            {
                results = deltaEngine.GetDifferences(tsLeftFile, tsRightFile, fileName =>
                                                         {
                                                             var deltaStrings = new List<DeltaString>();
                                                             using (var sr = new StreamReader(fileName))
                                                             {
                                                                 while (!sr.EndOfStream)
                                                                     deltaStrings.Add(new DeltaString(sr.ReadLine(), bCaseSensitive));
                                                             }
                                                             return deltaStrings;
                                                         });
            }

           // sw.Stop();
            //ElapsedTime = sw.Elapsed;
            //process.Refresh();
            //PeakMemoryUsage = process.PeakWorkingSet64 - peakWorkingSet64;

            return results;
        }
    }
}